﻿Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sexo() As String = {"M", "F"}
        Dim carrera() As String = {"PROGRAMADOR", "ANALISTA", "INGENIERO"}
        ComboBox2.Items.AddRange(sexo)
        ComboBox1.Items.AddRange(carrera)
        ComboBox1.Text = ComboBox1.Items.Item(0)
        ComboBox2.Text = ComboBox2.Items.Item(0)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click, Button3.Click
        Me.Close()
    End Sub

    Private Sub txtRut_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtRut.Validating
        ErrorProvider1.Clear()
    End Sub

    Private Sub txtNombre_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtNombre.Validating
        ErrorProvider1.Clear()
        If IsNumeric(txtNombre.Text) Then
            ErrorProvider1.SetError(txtNombre, "Nombre no es un valor numerico")
            txtNombre.Focus()
        Else
            ErrorProvider1.Clear()
        End If
    End Sub

    Private Sub ComboBox2_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ComboBox2.Validating
        ErrorProvider1.Clear()
        If ComboBox2.Text = "M" Or ComboBox2.Text = "F" Then
            ErrorProvider1.Clear()
        Else
            ErrorProvider1.SetError(ComboBox2, "debe ser M o F")
            ComboBox2.Focus()
        End If
    End Sub

    Private Sub ComboBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ComboBox1.Validating
        ErrorProvider1.Clear()
        If IsNumeric(ComboBox1.Text) Then
            ErrorProvider1.SetError(ComboBox1, "debe ingresar una carrera válida")
            ComboBox1.Focus()
        Else
            ErrorProvider1.Clear()
        End If
    End Sub

    Private Sub txtNotas_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtNotas.Validating
        ErrorProvider1.Clear()
        If Not IsNumeric(txtNotas.Text) Then
            ErrorProvider1.SetError(txtNotas, "debe ingresar una nota válida")
        Else
            ErrorProvider1.Clear()
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If IsNothing(txtRut.Text) Or IsNothing(txtNombre.Text) Or IsNothing(txtNotas.Text) Then
            ErrorProvider1.SetError(Button1, "ingrese datos en todo los campos")
            txtRut.Focus()
        Else
            Dim nvoalumno As New alumno(txtRut.Text, txtNombre.Text, ComboBox2.SelectedIndex, ComboBox1.SelectedIndex, NumericUpDown1.Value, txtNotas.Text)
            arralumno.Add(nvoalumno)
            MsgBox("Datos Ingresados Correctamente", MsgBoxStyle.Exclamation)
            limpia()
        End If
    End Sub

    Sub limpia()
        txtRut.Clear()
        txtNombre.Clear()
        txtNotas.Clear()
        ComboBox1.Text = ComboBox1.Items.Item(0)
        ComboBox2.Text = ComboBox2.Items.Item(0)
        NumericUpDown1.Value = 1
        txtRut.Focus()
    End Sub
End Class
